﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace XianboSite.Models
{

    public class UserAuthorizeAttribute : ActionFilterAttribute, IActionFilter//,IResultFilter
    {
        public string Authorize { get; set; }

        #region IActionFilter 成员

        void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
        {

        }

        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
            User user = HttpContext.Current.Session["CurrentUser"] as User;
            if (user == null)
            {
                filterContext.Result = new RedirectResult(@"/Home/Index");
            }
            else
            {
                filterContext.Controller.ViewData["CurrentUser"] = user;
            }
        }

        #endregion
    }
}